package woaini.wind.bot.code.impl.weChatFerry.auto;

import cn.hutool.core.collection.CollUtil;
import lombok.AllArgsConstructor;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.stereotype.Component;
import woaini.wind.bot.code.impl.weChatFerry.WeChatFerryBot;
import woaini.wind.bot.code.impl.weChatFerry.config.WeChatFerryBotAutoConfig;
import woaini.wind.bot.code.impl.weChatFerry.config.WeChatFerryBotConfig;
import woaini.wind.bot.core.boot.IBotAutoRegister;
import woaini.wind.bot.core.bot.Bot;

import java.util.ArrayList;
import java.util.List;

@Component
@EnableConfigurationProperties(WeChatFerryBotAutoConfig.class)
@AllArgsConstructor
public class WeChatFerryBotAutoRegister implements IBotAutoRegister {

  private final WeChatFerryBotAutoConfig weChatFerryBotAutoConfig;

  @Override
  public String name() {
    return WeChatFerryBot.NAME;
  }

  @Override
  public List<Bot> autoRegister() {

    List<Bot> botList = new ArrayList<>();

    List<WeChatFerryBotConfig> bots = weChatFerryBotAutoConfig.getBots();
    if (CollUtil.isEmpty(bots)) {
      return botList;
    }
    for (WeChatFerryBotConfig botConfig : bots) {
      WeChatFerryBot weChatFerryBot = new WeChatFerryBot(botConfig);
      botList.add(weChatFerryBot);
    }
    return botList;
  }
}
